package com.mx.web;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.plugins.Page;
import com.mx.entity.User;
import com.mx.mapper.UserMapper;
import com.mx.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author cyf
 * @since 2018-11-21
 */
@Controller
public class UserController {

    @Autowired
    private UserService userSvc;

    @Autowired
    private UserMapper userMapper;

    @GetMapping(value = "/show")
    @ResponseBody
    public JSONObject testEnum() {
        Page<User> users = userSvc.selectPage(new Page<>(1, 10));
        JSONObject result = new JSONObject();
        result.put("users", users);
        return result;
    }

    @GetMapping(value = "/get")
    @ResponseBody
    public JSONObject testGet() {
        User user = userMapper.selectById(1);
        return (JSONObject) JSONObject.toJSON(user);
    }
}
